/**
 * <p>Copyright (c) 2011 深圳市鹏途信息技术有限公司 </p>
 * <p>				   All right reserved. 		     </p>
 * 
 * <p>项目名称 ： 	东莞交通工程质量监督综合业务系统        </p>
 * <p>创建者   :	liuyang 
 * 
 * <p>描   述  :   SuperviserManager.java for com.pengtu.service.business    </p>
 * 
 * <p>最后修改 : $: 2011-8-25-下午2:02:05 v 1.0.0	 liuyang   $     </p>
 * 
 */

package com.pengtu.service.business;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.pengtu.dao.Page;
import com.pengtu.dao.QueryFilter;
import com.pengtu.dao.business.SuperviserDao;
import com.pengtu.entity.app.SupervisorGroup;
import com.pengtu.entity.business.Superviser;
import com.pengtu.entity.project.ProjectInfo;
import com.pengtu.service.BaseManager;

/**
 * 
 * SuperviserManager
 * 
 * 2011-8-25 下午2:02:05
 * 
 * @version 1.0.0
 * 
 */
@Component
@Transactional
public class SuperviserManager extends BaseManager {
	private SuperviserDao superviserDao;

	/**
	 * @param superviserDao
	 *            the superviserDao to set
	 */
	@Autowired
	public void setSuperviserDao(SuperviserDao superviserDao) {
		this.superviserDao = superviserDao;
	}

	/**
	 * 保存监督人员信息 save: 适用:
	 * 
	 * @param superviser
	 * @exception
	 * @since 1.0.0
	 */
	public void save(Superviser superviser) {
		superviserDao.save(superviser);
	}

	/**
	 * 根据ID查询 get: 适用:
	 * 
	 * @param id
	 * @return
	 * @exception
	 * @since 1.0.0
	 */
	public Superviser get(String id) {
		return superviserDao.get(id);
	}

	/**
	 * 查询所有监督人员 getAll: 适用:
	 * 
	 * @return
	 * @exception
	 * @since 1.0.0
	 */
	public List<Superviser> getAll() {
		return superviserDao.getAll();
	}

	/**
	 * 分页查询监督人员 search: 适用:
	 * 
	 * @param page
	 * @param queryFilter
	 * @return
	 * @exception
	 * @since 1.0.0
	 */
	public Page<Superviser> search(final Page<Superviser> page,
			final QueryFilter queryFilter) {
		return superviserDao.findPage(page, queryFilter);
	}

	/**
	 * 查询监督人员 getSupervisers: 适用:
	 * 
	 * @param projectId
	 * @param type
	 * @return
	 * @exception
	 * @since 1.0.0
	 */
	public List<Superviser> getSupervisers(String projectId, String type) {
		String hql = "select s from Superviser as s where s.projectInfo.id = :projectId and s.duty = :type";
		Map<String, String> values = new HashMap<String, String>();
		values.put("projectId", projectId);
		values.put("type", type);
		return superviserDao.find(hql, values);
	}
	@Transactional(readOnly=true)
	public List<Superviser> findByProperty(String propertyName, String value) {
		// TODO Auto-generated method stub
		return superviserDao.findBy(propertyName, value);
	}

	public void add(ProjectInfo projectInfo,
			List<SupervisorGroup> supervisorGroups, Date startDate, Date endDate) {
		for (SupervisorGroup supervisorGroup : supervisorGroups) {
			Superviser superviser = new Superviser();
			superviser.setDuty(supervisorGroup.getDuty());
			superviser.setPhone(supervisorGroup.getPhone());
			superviser.setProjectInfo(projectInfo);
			superviser.setUser(supervisorGroup.getOfficer());
			superviser.setRemark(supervisorGroup.getRemark());
			superviser.setGroupName(supervisorGroup.getSuperviseGroup()
					.getName());
			superviser.setEndDate(endDate);
			superviser.setStartDate(startDate);
			superviserDao.save(superviser);
		}
	}
	
	public void delete(Superviser superviser){
		superviserDao.delete(superviser);
	}

}
